cmake_minimum_required(VERSION 3.13)

include_directories(${VU_HEADERS} ${VU_DYN_HEADER_PATH})
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)

file(GLOB VUFUSE_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/vu*.c)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64")

foreach(VUFUSE_MOD ${VUFUSE_MODULES})
    string(REGEX REPLACE "\.c$" "" VUFUSE_MOD_FILE ${VUFUSE_MOD})
    get_filename_component(VUFUSE_MOD_TARGET ${VUFUSE_MOD_FILE} NAME)
    add_library(${VUFUSE_MOD_TARGET} SHARED ${VUFUSE_MOD})
    set_target_properties(${VUFUSE_MOD_TARGET} PROPERTIES PREFIX "")
		target_compile_definitions(${VUFUSE_MOD_TARGET} PUBLIC PROGNAME="${VUFUSE_MOD_TARGET}")
    install(TARGETS ${VUFUSE_MOD_TARGET} LIBRARY DESTINATION ${MODULES_INSTALL_PATH})
endforeach(VUFUSE_MOD)

foreach(VUFUSE_MOD ${VUFUSE_MODULES})
    string(REGEX REPLACE "\.c$" "" VUFUSE_MOD_FILE ${VUFUSE_MOD})
    get_filename_component(VUFUSE_MOD_EXE ${VUFUSE_MOD_FILE} NAME)
    string(REGEX REPLACE "^vu" "" VUFUSE_MOD_EXE ${VUFUSE_MOD_EXE})
		set(VUFUSE_MOD_TARGET ${VUFUSE_MOD_EXE})
    add_executable(${VUFUSE_MOD_TARGET} ${VUFUSE_MOD})
		set_target_properties(${VUFUSE_MOD_TARGET} PROPERTIES OUTPUT_NAME ${VUFUSE_MOD_EXE})
		target_compile_definitions(${VUFUSE_MOD_TARGET} PUBLIC PROGNAME="${VUFUSE_MOD_TARGET}")
    target_link_libraries(${VUFUSE_MOD_TARGET} -lfuse)
    install(TARGETS ${VUFUSE_MOD_TARGET} RUNTIME DESTINATION bin)
endforeach(VUFUSE_MOD)
